//
//  NSMutableArray+TYSafe.h
//  TYFoundationUtils
//
//  Created by devp on 1/25/16.
//  Copyright © 2016 ND. All rights reserved.
//

#import <Foundation/Foundation.h>

#ifndef TYArrayAddObject
#define TYArrayAddObject(array, object)   \
if (object) {         \
[(array) addObject:(object)];  \
}
#endif

#ifndef TYArrayInsertObjectAtIndex
#define TYArrayInsertObjectAtIndex(array, object, index)                       \
if ((object) && (index) <= [(array) count] && (index) >= 0) {          \
[(array) insertObject:(object) atIndex:(index)];                   \
}
#endif

#ifndef TYArrayObjectAtIndex
#define TYArrayObjectAtIndex(array, index)                                     \
((index) < [(array) count] && (index) >= 0 ?                           \
[(array) objectAtIndex:(index)] : nil)
#endif

#ifndef TYArrayRemoveObjectAtIndex
#define TYArrayRemoveObjectAtIndex(array, index)                               \
if ((index) < [(array) count] && (index) >= 0) {                       \
[(array) removeObjectAtIndex:(index)];                             \
}
#endif

#ifndef TYArrayReplaceObjectAtIndex
#define TYArrayReplaceObjectAtIndex(array, object, index)                      \
if ((object) && (index) < [(array) count] && (index) >= 0) {           \
[(array) replaceObjectAtIndex:(index) withObject:(object)];        \
}
#endif

@interface NSMutableArray (TYSafe)

@end
